[assembly: System.Reflection.AssemblyDescription("QA-Tools-12")]

namespace QAToolsAddin {
    using System;
    using Extensibility;
    using System.Runtime.InteropServices;
    using Excel = Microsoft.Office.Interop.Excel;
    using Core = Microsoft.Office.Core;
    using System.Drawing;

    [GuidAttribute("FA5EC8F4-B134-45FB-9075-746D14E5372F"), ComVisible(true)]
    public interface IConnect : Extensibility.IDTExtensibility2, Core.IRibbonExtensibility {
        void Test();
        void Ribbon_Load(Core.IRibbonUI ribbonUi);
        bool GetEnabled(Core.IRibbonControl control);
        Bitmap GetImage(string imageName);
        void OnClick(Core.IRibbonControl control);
    }

    [GuidAttribute("5E934B55-8283-4167-B273-7F2EBF363A52"), ProgId("QAToolsAddin.Connect"), ComVisible(true), ComDefaultInterface(typeof(IConnect)), ClassInterface(ClassInterfaceType.None)]
    public partial class Connect : ConnectBase, IConnect {
        private Core.IRibbonUI _ribbon;

        public Connect() {
        }

        public void Ribbon_Load(Core.IRibbonUI ribbonUi) {
            _ribbon = ribbonUi;
            Undo.SetButtonEnabled += enable => SetRibbonControlEnabled("btUndo_Click", enable);
        }

        public void SetRibbonControlEnabled(string controlName, bool enable) {
            _commands.SetControlEnabled(controlName, enable);
            _ribbon.InvalidateControl(controlName);
        }

        public bool GetEnabled(Core.IRibbonControl control) {
            return _commands.GetControlEnabled(control.Id);
        }

        public System.Drawing.Bitmap GetImage(string imageName) {
            var bitmap = (System.Drawing.Bitmap)Properties.Resources.ResourceManager.GetObject(imageName);
            if (bitmap == null) return null;
            bitmap.MakeTransparent(System.Drawing.Color.Magenta);
            return bitmap;
        }

        string Core.IRibbonExtensibility.GetCustomUI(string ribbonId) {
            return Properties.Resources.Ribbon;
        }

        public void OnClick(Core.IRibbonControl control) {
            _commands.InvokeAction(control.Id);
        }

    }
}